package com.nulldev.util.os.nullInstaller;

import com.nulldev.util.io.CLI;
import com.nulldev.util.java.JVMUtil;
import com.nulldev.util.java.swing.SwingUtil;
import com.nulldev.util.os.OSUtil;
import com.nulldev.util.other.ArrayUtils;

import static com.nulldev.util.java.JVMUtil.*;

import com.nulldev.util.FinalBypass;

public class nullInstaller {
	
	public static final FinalBypass<Boolean> isX11safe = new FinalBypass<Boolean>(false);

	public static void main(String[] args) {
		JVMUtil.setArgs(args);
		final CLI argv = new CLI(args);
		
		if ((!OSUtil.isLinux() && !OSUtil.isWindows()) && !JVMUtil.isArg("--system.bypassInvalidOSCheck")) {
			async_error("Error: Unsupported operating system.");
			System.exit(-1);
			return;
		}
		
		isX11safe.setObject(SwingUtil.isX11Safe());
		isX11safe.lock();
		
		if (!isX11safe.getObject()) {
			SwingUtil.enableHeadless();
		}
		
		if (args.length == 0) {
			async_println("nullInstaller: No operation provided, displaying help.");
			helpDialog();
			return;
		}
		final String operation = args[0];
		if (operation == null || operation.length() == 0) {
			helpDialog();
			return;
		}else if (operation.equals("about")) {
			async_println("ni/nullInstaller, build 1.00.00");
			return;
		}else {
			async_println("Unknown operation: " + operation);
			helpDialog();
			return;
		}
	}
	
	private static void helpDialog() { 
		async_println("install [packages] - This will install packages provided by the user.");
		async_println("update [packages] - This will update the selected packages.");
		async_println("about - Information about ni/nullInstaller");
		System.exit(-1);
	}
	
	public static String[] parsePackages(final String[] args) {
		return ArrayUtils.from(args, 1);
	}

}
